﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Abp.AspNetCore.Mvc.Authorization;
using Abp.AutoMapper;
using KelonProud.Administration.Dtos;
using KelonProud.Administration.Managers.Application;
using KelonProud.Administration.Managers.Authorization;
using KelonProud.Administration.Managers.MultiTenancy;
using KelonProud.Administration.Managers.Organizations;
using KelonProud.Mvc;
using Microsoft.AspNetCore.Mvc;

namespace KelonProud.Administration.Controllers
{
    [AbpMvcAuthorize]
    [Route("admin/[controller]/[action]")]
    public class OrganizationController : KelonProudControllerBase
    {
        private readonly KenlonOrganizationManager _kenlonOrganizationManager;

        public OrganizationController(KenlonOrganizationManager kenlonOrganizationManager)
        {
            _kenlonOrganizationManager = kenlonOrganizationManager;
        }


        public ActionResult Index()
        {
            return View("KelonProud.Administration.Views.Organization.Index");
        }

        public ActionResult Create(int? parentId)
        {
            var model = new OrganzationInput
            {
               TenantId = AbpSession.TenantId,
               ParentId = parentId
            };

            return View("KelonProud.Administration.Views.Organization.Edit", model);
        }

        public ActionResult Edit(int id)
        {
            var nav = _kenlonOrganizationManager.GetById(id);

            if (nav == null)
                throw new Exception("需要编辑的机构不存在!");

            var model = nav.MapTo<OrganzationInput>();

            return View("KelonProud.Administration.Views.Organization.Edit", model);
        }

        public ActionResult SelectUsers(int orgId)
        {
            return View("KelonProud.Administration.Views.Organization.SelectUsers", orgId);
        }
    }
}
